<!DOCTYPE HTML>
<html>

<head>

	<title>TradingView Charting Library demo</title>
	<!-- Fix for iOS Safari zooming bug -->
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="IE=Edge">
	<script type="text/javascript" src="charting_library/charting_library.min.js"></script>
	<script type="text/javascript" src="datafeeds/udf/dist/polyfills.js"></script>
	<script type="text/javascript" src="datafeeds/udf/dist/bundle.js"></script>
	<script src="./jq.js"></script>
	<!-- <script src="./datafeeds/datafeeds copy 2.js"></script> -->
	<script src="./datafeeds/datafeeds.js"></script>
	<script type="text/javascript">

		function getParameterByName(name) {
			name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
			var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
				results = regex.exec(location.search);
			return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
		}
		var datafeed = datafeed
		TradingView.onready(function () {
			var widget = window.tvWidget = new TradingView.widget({
				// debug: true, // uncomment this line to see Library errors and warnings in the console
				fullscreen: true,
				symbol: 'BTC/USDT',
				interval: '5',
				container_id: "tv_chart_container",
				//	BEWARE: no trailing slash is expected in feed URL
				// datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com"),
				datafeed: datafeed,
				library_path: "charting_library/",
				locale: getParameterByName('lang') || "en",
				disabled_features: ["use_localstorage_for_settings"],
				enabled_features: ["study_templates"],
				charts_storage_url: '',
				charts_storage_api_version: "1.1",
				client_id: 'tradingview.com',
				user_id: 'public_user_id',
				// theme: getParameterByName('theme'),
				theme:"black",
				// preset: "mobile",
				custom_css_url: 'chart.css',
				disabled_features: [ //开启图表功能的字符串文字允许将用户设置保存到本地存储
                    'header_symbol_search', //头部搜索
                    'header_widget_dom_node', //隐藏头部组件
                    'source_selection_markers', //禁用系列和指示器的选择标记
                    'header_indicators', //图标指标
                    'adaptive_logo', //移动端可以隐藏logo
                    'constraint_dialogs_movement',
                    'header_interval_dialog_button',
                    'show_interval_dialog_on_key_press',
                    'symbol_search_hot_key',
                    'study_dialog_search_control',
                    'display_market_status',
                    'header_chart_type', // k线样式
                    'header_compare', //图表对比
                    'header_undo_redo', //撤销返回
                    'header_screenshot', //截图
                    'volume_force_overlay', //防止他们重叠
                    'header_settings', //设置
					'property_pages', //禁用所有属性页
                    // 'header_fullscreen_button', //全屏
                    'header_saveload',
                    'edit_buttons_in_legend',
                    'timeframes_toolbar', //下面的时间
                    'symbol_info',
                    'border_around_the_chart',
                    'main_series_scale_menu',
                    'star_some_intervals_by_default',
                    'datasource_copypaste',
                    'right_bar_stays_on_scroll',
                    'context_menus',
                    'go_to_date',
                    'compare_symbol',
                    'border_around_the_chart',
                    'timezone_menu',
                    'header_resolutions', // todo：przetestowac //头部的时间
                    'control_bar', // todo：przetestowac
                    'edit_buttons_in_legend', // todo：przetestowac
                    'remove_library_container_border',
                ],
                enabled_features: [
                    "dont_show_boolean_study_arguments",
                    "use_localstorage_for_settings",
                    "remove_library_container_border",
                    "save_chart_properties_to_local_storage",
                    "side_toolbar_in_fullscreen_mode",
                    "hide_last_na_study_output",
                    "constraint_dialogs_movement", //todo: nie do końca jestem pewien
				],
                overrides: {
                    "paneProperties.background": "#111D2D",//背景色
                    "paneProperties.vertGridProperties.color": "#252525",//横向线颜色
                    "paneProperties.horzGridProperties.color": "#252525",//竖向线颜色
                    // "symbolWatermarkProperties.transparency": 90,
					"scalesProperties.textColor": "#61688a",//文字颜色
                },
			});
			widget.onChartReady(function () {
				widget.chart().setResolution('5');
				widget.chart().setChartType(1);
				widget.MALine5 = widget.chart().createStudy('Moving Average', false, false, [5], null, { 'Plot.color': '#5E53C6' });
				widget.MALine10 = widget.chart().createStudy('Moving Average', false, false, [10], null, { 'Plot.color': '#7cacc2' });
				widget.MALine30 = widget.chart().createStudy('Moving Average', false, false, [30], null, { 'Plot.color': '#45B765' });
				widget.MALine60 = widget.chart().createStudy('Moving Average', false, false, [60], null, { 'Plot.color': '#B7225E' });
				var timeList = ['time', '1min', '5min', '15min', '30min', '60min', '1day']
				var times = ['1', '1', '5', '15', '30', '60', 'D']
				timeList.forEach(function (v, i) {
					var button = widget.createButton();
					button.attr('title', v)
					button.append($('<span>' + v + '</span>'))
					button.on('click', function (a) {
						if (v === 'time') {
							$($(a)[0].target).parents().siblings().find('.red').removeClass('red')
							$($(a)[0].target).addClass('red')
							widget.chart().setChartType(3)
						} else {
							widget.chart().setResolution(times[i], function () {
								$($(a)[0].target).parents().siblings().find('.red').removeClass('red')
								$($(a)[0].target).addClass('red')
								widget.chart().setChartType(1)
							})
						}
					})
				})
			});
		});

	</script>

</head>

<body style="margin:0px;">
	<div id="tv_chart_container"></div>
</body>

</html>